//
// Created on 2024/4/18.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#ifndef _NAPI_HELPER_H_
#define _NAPI_HELPER_H_

#include "napi/JsFunction.h"
#include <unordered_map>


class NapiHelper {

public:
    /**
     * 注册Js接口
     * @param name
     * @param jsFunction
     */
    void registerNapiFunction(std::string name, JsFunction *jsFunction);

    JsFunction getFunction(std::string functionName) { return FUNCTION_MAP.at(functionName); }

    void addFunction(std::string name, JsFunction *jsFunction) { FUNCTION_MAP.emplace(name, *jsFunction); }

    static NapiHelper &GetInstance();

private:
    // 禁止外部构造
    NapiHelper();

    // 禁止外部析构
    ~NapiHelper();

    // 禁止外部拷贝构造
    NapiHelper(const NapiHelper &single) = delete;

    // 禁止外部赋值操作
    const NapiHelper &operator=(const NapiHelper &single) = delete;

    /**
     * 用于保存Js方法
     */
    std::unordered_map<std::string, JsFunction> FUNCTION_MAP;
};

#endif